import 'dart:ui';

import 'package:flutter/widgets.dart';

class JrBlurContainer extends Container {
  final double sigmaX;
  final double sigmaY;
  final BorderRadius? outerRadius;
  JrBlurContainer({
    Key? key,
    AlignmentGeometry? alignment,
    EdgeInsetsGeometry? padding,
    Color? color,
    Decoration? decoration,
    Decoration? foregroundDecoration,
    double? width,
    double? height,
    BoxConstraints? constraints,
    EdgeInsetsGeometry? margin,
    Matrix4? transform,
    AlignmentGeometry? transformAlignment,
    Widget? child,
    Clip clipBehavior = Clip.none,
    this.sigmaX = 10.0,
    this.sigmaY = 10.0,
    this.outerRadius,
  }) : super(
          key: key,
          alignment: alignment,
          padding: padding,
          color: color,
          decoration: decoration,
          foregroundDecoration: foregroundDecoration,
          width: width,
          height: height,
          constraints: constraints,
          margin: margin,
          transform: transform,
          transformAlignment: transformAlignment,
          child: child,
          clipBehavior: clipBehavior,
        );

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
        borderRadius: outerRadius ?? BorderRadius.zero,
        clipBehavior: Clip.hardEdge,
        child: BackdropFilter(
          filter: ImageFilter.blur(sigmaX: sigmaX, sigmaY: sigmaY),
          child: super.build(context),
        ));
  }
}

// class JrBlurContainer extends Container {
//   @override
//   Widget build(BuildContext context) {
//     return Container(
//       decoration: BoxDecoration(),
//       child: ClipRect(
//         child: BackdropFilter(
//           filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
//           child: super.build(context),
//         ),
//       ),
//     );
//   }
// }
// class BlurDecoration extends BoxDecoration {
//   final Decoration? decoration;
//   final double sigmaX;
//   final double sigmaY;

//   const BlurDecoration({
//     this.decoration,
//     this.sigmaX = 5.0,
//     this.sigmaY = 5.0,
//   });

//   @override
//   BoxPainter createBoxPainter([VoidCallback? onChanged]) {
//     return _BlurDecorationPainter(
//       decoration: decoration,
//       sigmaX: sigmaX,
//       sigmaY: sigmaY,
//     );
//   }
// }

// class _BlurDecorationPainter extends BoxPainter {
//   final Decoration? decoration;
//   final double sigmaX;
//   final double sigmaY;

//   _BlurDecorationPainter({
//     this.decoration,
//     required this.sigmaX,
//     required this.sigmaY,
//   });

//   @override
//   void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
//     if (decoration != null) {
//       final paint = Paint()..imageFilter = ImageFilter.blur(sigmaX: sigmaX, sigmaY: sigmaY);
//       final decorationPainter = decoration!.createBoxPainter();

//       canvas.saveLayer(offset & configuration.size!, paint);
//       decorationPainter.paint(canvas, offset, configuration);
//       canvas.restore();
//     }
//   }
// }